﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BLL
{
	public class ActionResult
	{
        string action;
		public List<Exception> Exceptions { get; set; }

        public bool Success
        {
            get { return !Exceptions.Any(); }
            
            // set { Success = value; }
        }
        public ActionResult()
        {
            Exceptions = new List<Exception>();
        }
		public ActionResult(string _act)
		{
            action = _act;
			Exceptions = new List<Exception>();
		}

		public string GetErrorMessages()
		{
			var sb = new StringBuilder();
			Exceptions.ForEach(e => sb.AppendLine(e.Message));
			return sb.ToString();
		}
        public void Show()
        {
            if (Success)
            {
                MessageBox.Show(action + " thành công");
            }
            else
            {
                MessageBox.Show(GetErrorMessages(), "Error!", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }
	}

	public class ActionResult<T> : ActionResult
	{
		public T Result { get; set; }
	}

	public class ActionResultAsList<T> : ActionResult
	{
        public ActionResultAsList()
        {
            Result = new List<T>();
        }
		public List<T> Result { get; set; }
	}
}
